package com.wuwei.aliocr.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wuwei.aliocr.domain.LessonRecord;
import com.wuwei.aliocr.domain.ShangKeRiQi;
import com.wuwei.aliocr.domain.Subject;
import com.wuwei.aliocr.domain.Teacher;
import com.wuwei.aliocr.enumPackage.ModelEnum;
import com.wuwei.aliocr.exception.PaiKeException;
import com.wuwei.aliocr.mapper.LessonRecordMapper;
import com.wuwei.aliocr.mapper.ShangKeRiQiMapper;
import com.wuwei.aliocr.mapper.SubjectMapper;
import com.wuwei.aliocr.mapper.TeacherMapper;
import com.wuwei.aliocr.service.LessonRecordService;
import com.wuwei.aliocr.utils.CommonUtils;
import lombok.SneakyThrows;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;

@Service
public class LessonRecordServiceImpl implements LessonRecordService {

    @Resource
    private LessonRecordMapper lessonRecordMapper;

    @Resource
    private TeacherMapper teacherMapper;

    @Resource
    private ShangKeRiQiMapper shangKeRiQiMapper;

    @Resource
    private SubjectMapper subjectMapper;

    @Resource
    private CommonUtils commonUtils;

    /**
     * 用于改变课表中上课人的方法，常用于调整课表使用，比如某人需要由谁代课
     *
     * @param date
     * @param subject
     * @param time
     * @param teacherId
     */
    @Override
    @Transactional
    public void updateTeacher(String date, String subject, String time, String teacherId) {
        //查出teacherId对应的教员姓名
        Teacher teacher = teacherMapper.selectById(teacherId);
        String teacherName = teacher.getName();
        //需要查询该名教员当天该时间段有无其他课程安排
        LambdaQueryWrapper<LessonRecord> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(teacherName!=null,LessonRecord::getTeacher,teacherName)
                .eq(time!=null,LessonRecord::getTime,time)
                .eq(date!=null,LessonRecord::getDate,date);
        List<LessonRecord> lessonRecords = lessonRecordMapper.selectList(queryWrapper);
        if (lessonRecords.size()==0) {
            lessonRecordMapper.updateByDateSubjectTime( date,  subject,  time,teacherName);
        }
        else {
            throw new PaiKeException(30001,"修改失败，该名教员当天已有其他教学任务");
        }
    }

    /**
     * 向服务器发送请求进行排课，排完课返回一个EXCEL文件，要求用户检查完后上传回来
     * @param model    排的某个指定的课程模块
     * @param teachers 指定哪几位教师
     * @param date     从哪天开始排课
     * @param time     第一节课的时间
     * @param savePath 本地的存放路径
     */
    @Override
    @Transactional
    @SneakyThrows
    public void startPaike(String model, List<String>teachers, Date date, String time, String savePath,String remark) {
        //写一个excel文件
        /*
        1.写日期和时间和星期以及周六日
        2.写课程和类型以
        3.写教师
        4.写备注-remark及课时
         */
        //1写日期和时间和星期以及周六日
        List<LessonRecord> lessonRecordList = setDateAndTimeAndWeekend(model, date, time);
        //2写课程和类型
        lessonRecordList = setSubjectAndType(lessonRecordList,model);
        //写教师
        lessonRecordList = setTeacher(lessonRecordList,teachers,model);
    }

    /**
     * 安排教师排课
     * @param lessonRecordList 排课计划的list集合，需要对里面每一个元素进行课程和类型的设置
     * @param teachers 传入的可以上这门课的教师的集合
     * @return
     */
    private List<LessonRecord> setTeacher(List<LessonRecord> lessonRecordList, List<String> teachers,String model) {
        /*
        进行某个模块教师排课需要注意的地方
        1.除了M1以外，其余的模块都不能让一个教师连续上6节课
        2.在安排某位教师时，需要去数据库查询一下他当天有没有其他教学任务，如果有其他教学任务就不能安排上课
        3.安排时先让某一个教师先上课，上3天后再换下一个教师
         */

        if ("M1".equals(model)) {
            // TODO 这里的第一个元素是学前教育，讲师是班主任，后续需要将班主任加入进来
            setM1ModelTeacher(lessonRecordList, teachers);
        } else {
            setOtherModelTeacher(lessonRecordList, teachers ,model);
        }
        return lessonRecordList;
    }

    /**
     * 设置M1模块的教师安排
     * @param lessonRecordList
     * @param teachers
     */
    private void setM1ModelTeacher(List<LessonRecord> lessonRecordList, List<String> teachers) {
        int teachersSize = teachers.size();
        if (teachersSize == 1) {
            String teacher = teachers.get(0);
            //只有一名教员，此时需要查询该名教员在这段上课期间有无其他工作安排
           lessonRecordList.forEach(a->{
               String time = a.getTime();
               String date = commonUtils.mySqlDateFormatDateDashToString(a.getDate());
               LambdaQueryWrapper<LessonRecord> queryWrapper = new LambdaQueryWrapper<>();
               queryWrapper.eq(time!=null,LessonRecord::getTime,time).eq(date!=null,LessonRecord::getDate,date).eq(teacher!=null,LessonRecord::getTeacher,teacher);
               List<LessonRecord> selectList = lessonRecordMapper.selectList(queryWrapper);
               if (selectList.size()>0) {
                   String message = "排课失败，"+teacher+"，该名教员已有其他教学任务！";
                   throw  new PaiKeException(30002,message);
               }
           });
            //程序能走到这里说明该名教员在这段时间内没有其他工作任务
            lessonRecordList.forEach(a->{
                String date = commonUtils.mySqlDateFormatDateDashToString(a.getDate());
                boolean flag = searchIfThisTeacherWorkForMoreThan40Hours(teacher,date);
                addThisTeacherToLessonRecordList(a, teacher, flag);
            });
        } else if (teachersSize >1 ) {//M1最多安排两名教师就够了
            scheduleTeacherWhenTeachersSizeBiggerThanTwo( lessonRecordList,  teachers);
//            for (int i = 0; i < lessonRecordList.size(); i++) {
//                int index = 0;
//                LessonRecord lessonRecord = lessonRecordList.get(i);
//                String time = lessonRecord.getTime();
//                if (i == 0) {
//                    //M1的第一节课是09:00-10:30需要将其转换成08:30-10:30
//                    time = "08:30-10:30";
//                }
//                String date = commonUtils.mySqlDateFormatDateDashToString(lessonRecord.getDate());
//                scheduleTeacherWhenTeachersSizeBiggerThanTwo(teachers, lessonRecord,time,date);
//                String date = commonUtils.mySqlDateFormatDateDashToString(lessonRecord.getDate());
//                //需要查询该名教员在这个time和date有没有工作
//                if (i < (lessonRecordList.size()/2)) {
//                    scheduleTeacherWhenTeachersWereTwo(teachers, index, lessonRecord, time, date);
//                }else {
//                    //这里需要写后面2天的课程安排
//                    index=1;
//                    scheduleTeacherWhenTeachersWereTwo(teachers, index, lessonRecord, time, date);
//                }
//            }

        }
    }

    /**
     * 当传入教师的数量大于1的时候对M1进行排课
     */
    private void scheduleTeacherWhenTeachersSizeBiggerThanTwo(List<LessonRecord> lessonRecordList, List<String> teachers ) {
        /*
        当教师数量大于1的时候对M1进行排课需要注意的有
        1.最多安排两名教师上课
        2.安排教师上课一上就上一整天
        3.一名教员上两天，但是先把所有教师都查一遍，看能否满足一名教师上两天的条件
        4.找出能满足一名教师上两天的条件后就可以进行排课了
        5.上述条件做不到就报异常
         */
        //找出能上课的教师
        int size = teachers.size();
        Date firstDate = lessonRecordList.get(0).getDate();
        Date middleDate = lessonRecordList.get(7).getDate();
        Date lastDate = lessonRecordList.get(lessonRecordList.size()-1).getDate();
        List<String> workTeachersList = new ArrayList<>();
        AtomicBoolean foundFirstTeacher = new AtomicBoolean(false);
        AtomicBoolean foundSecondTeacher = new AtomicBoolean(false);
        //先找能上前两天的教师
        findIfTeacherCanWorkTwoDays(teachers, firstDate, middleDate, workTeachersList, foundFirstTeacher);
        //再找能上后两天的教师
        findIfTeacherCanWorkTwoDays(teachers, middleDate, lastDate, workTeachersList, foundSecondTeacher);
        //程序走到这里说明教员找到了，开始排课
        //程序能走到这里说明该名教员在这段时间内没有其他工作任务,开始排课
        for (int i = 0; i < lessonRecordList.size()/2; i++) {
            LessonRecord lessonRecord = lessonRecordList.get(i);
            String date = commonUtils.mySqlDateFormatDateDashToString(lessonRecord.getDate());
            String teacher = workTeachersList.get(0);
            boolean flag = searchIfThisTeacherWorkForMoreThan40Hours(teacher,date);
            addThisTeacherToLessonRecordList(lessonRecord, teacher, flag);
        }
        for (int i = lessonRecordList.size()/2; i < lessonRecordList.size(); i++) {
            LessonRecord lessonRecord = lessonRecordList.get(i);
            String date = commonUtils.mySqlDateFormatDateDashToString(lessonRecord.getDate());
            String teacher = workTeachersList.get(1);
            boolean flag = searchIfThisTeacherWorkForMoreThan40Hours(teacher,date);
            addThisTeacherToLessonRecordList(lessonRecord, teacher, flag);
        }
    }

    /**
     * 判断某个教员能否在两个日期区间内连续工作2天的方法，如果能，则将其加入到workTeachersList中
     * @param teachers
     * @param firstDate
     * @param middleDate
     * @param workTeachersList
     * @param foundFirstTeacher
     */
    private void findIfTeacherCanWorkTwoDays(List<String> teachers,  Date firstDate, Date middleDate, List<String> workTeachersList, AtomicBoolean foundFirstTeacher) {
        int size = teachers.size();
        for (int i = 0; i < size; i++) {
            String teacher = teachers.get(i);
            LambdaQueryWrapper<LessonRecord> firstQw = new LambdaQueryWrapper<>();
            firstQw.eq(teacher!=null,LessonRecord::getTeacher,teacher).between((firstDate!=null)&&(middleDate!=null),LessonRecord::getDate,firstDate,middleDate);
            List<LessonRecord> selectList = lessonRecordMapper.selectList(firstQw);
            if (selectList.size()==0) {
                workTeachersList.add(teacher);
                foundFirstTeacher.set(true);
                break;
            }
        }
        //如果没找到能上前两天的教师，就报异常
        if (!foundFirstTeacher.get()) {
            throw new PaiKeException(30002,"排课失败，对M1进行排课时不满足一人上两天的条件！");
        }
    }

    /**
     * 查询该名教员本周是否工作超过了40个小时
     * @param teacher
     * @param date
     * @return 如果该名教员在前5天工作了5个整工作日，返回true，否则返回false
     */
    private boolean searchIfThisTeacherWorkForMoreThan40Hours(String teacher, String date) {
        //找到date的前三天
        LocalDate formattedDate = LocalDate.parse(date);
        LocalDate result = formattedDate.minusDays(6);
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        String theDayMinusSixDays = result.format(formatter);
        Integer integer = lessonRecordMapper.searchIfThisTeacherWorkForMoreThan40Hours(teacher, date, theDayMinusSixDays);
            return integer==20;
    }

    /**
     * 当教师数量为2时传入教师名称列表和每次循环的索引i，每次循环都等于一次重新排课，如果排完课发现改名教师已经有其他任务了，则更换下一名教师
     * @param teachers
     * @param index
     * @param lessonRecord
     * @param time
     * @param date
     */
    private void scheduleTeacherWhenTeachersWereTwo(List<String> teachers, int index, LessonRecord lessonRecord, String time, String date) {
        String teacher1 = teachers.get(index);
        LambdaQueryWrapper<LessonRecord> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(time != null, LessonRecord::getTime, time).eq(date != null, LessonRecord::getDate, date).eq(teacher1 != null, LessonRecord::getTeacher, teacher1);
        List<LessonRecord> selectList = lessonRecordMapper.selectList(queryWrapper);
        if (selectList.size() > 0) {
            //TODO 这里如果该名教员在当前时间段有其他工作需要换成别的教员来做此份工作，并且这里的代码有点冗余，需要想办法通过while循环或者递归来解决此问题
            //看看另外一名教员有没有工作安排，如果另外一名教员也有工作安排则抛出异常
            //TODO 这里代码有点问题，如果此时传入的教员超过2名教员，但是这个时候只会查询前两名教员有没有教学任务，都有教学任务就会抛出异常，但是他没有查后面的教员有没有教学任务
            index++;
            String otherTeacher = teachers.get(index);
            LambdaQueryWrapper<LessonRecord> queryWrapper1 = new LambdaQueryWrapper<>();
            queryWrapper1.eq(time != null, LessonRecord::getTime, time).eq(date != null, LessonRecord::getDate, date).eq(teacher1 != null, LessonRecord::getTeacher, otherTeacher);
            List<LessonRecord> selectList1 = lessonRecordMapper.selectList(queryWrapper1);
            if (selectList1.size() > 0) {
                String message = "排课失败，" + otherTeacher + "在" + date + "已有其他教学任务！";
                throw new PaiKeException(30002, message);
            }
            else {
                //否则将这名教员添加到授课列表中
                boolean flag = searchIfThisTeacherWorkForMoreThan40Hours(otherTeacher,date);
                addThisTeacherToLessonRecordList(lessonRecord, otherTeacher, flag);
            }
        } else {
            boolean flag = searchIfThisTeacherWorkForMoreThan40Hours(teacher1,date);
            addThisTeacherToLessonRecordList(lessonRecord, teacher1, flag);
        }
    }

    /**
     * 否则将这名教员添加到授课列表中
     * @param lessonRecord 单独的某节课的安排
     * @param teacher 老师姓名
     * @param flag 是否能将该名教员添加到列表的标记，如果是true则抛出异常
     */
    private void addThisTeacherToLessonRecordList(LessonRecord lessonRecord, String teacher, boolean flag) {
        if (!flag) {
            lessonRecord.setTeacher(teacher);
        } else {
            Date aDate = lessonRecord.getDate();
            String message = "排课失败，" + teacher + "，该名教员在" + aDate + "已连续工作六天！";
            throw new PaiKeException(30002, message);
        }
    }

    /**
     * 设置除了M1模块以外其他模块的教师安排
     * @param lessonRecordList
     * @param teachers
     * @param model
     */
    private void setOtherModelTeacher(List<LessonRecord> lessonRecordList, List<String> teachers, String model) {
        /*
           进行某个模块教师排课需要注意的地方
        1.除了M1以外，其余的模块都不能让一个教师连续上6节课
        2.在安排某位教师时，需要去数据库查询一下他当天有没有其他教学任务，如果有其他教学任务就不能安排上课
        3.安排时先让某一个教师先上课，上3天后再换下一个教师
        4.除了M1基本都是至少2名教员授课，这里的做法就是一人上三天
         */
        //这里前端已经帮我们做过校验了，不需要考虑teachers的size等于1的情况
        int teachersSize = teachers.size();
        List<String> teacherList = new ArrayList<>();
        for (int i = 0; i < lessonRecordList.size(); i++) {
            LessonRecord lessonRecord = lessonRecordList.get(i);
            int index = i/12;
            int t = index%teachersSize;
            teacherList.add(teachers.get(index>=teachersSize?t:index));
        }
        teacherList.forEach(System.out::println);
        //拿到了教师的排课计划列表，下面需要对这个列表进行调整，需要逐个查看老师上课的这三天是否有其他任务
        //TODO 这里按照teacher循环排课即可，要注意
            /*
            1.每名教员排3天课，排课之前先查一下这3天该名教员有没有课安排，如果有课程安排则换一名教员排3天课，如果所有的教员3天以内都有课程安排，就给这名教员排2天课，如果2天课也排不出来就报异常
            2.查询好没问题后，在看看该名教员是否连续上了40小时课
             */
    }

//    /**
//     * 设置M1模块的教师安排
//     * @param lessonRecordList
//     * @param teachers
//     */
//    private void setM1ModelTeacher(List<LessonRecord> lessonRecordList, List<String> teachers) {
//        int teachersSize = teachers.size();
//        if (teachersSize == 1) {
//            lessonRecordList.forEach(a->a.setTeacher(teachers.get(0)));
//        } else if (teachersSize ==2 ) {
//            String firstTeacher = teachers.get(0);
//            String secondTeacher = teachers.get(1);
//            for (int i = 0; i < lessonRecordList.size(); i++) {
//                LessonRecord lessonRecord = lessonRecordList.get(i);
//                if (i < (lessonRecordList.size()/2)) {
//                    lessonRecord.setTeacher(firstTeacher);
//                } else {
//                    lessonRecord.setTeacher(secondTeacher);
//                }
//            }
//        } else {
//            String firstTeacher = teachers.get(0);
//            String secondTeacher = teachers.get(1);
//            String thirdTeacher = teachers.get(2);
//            //否则说明教师数量大于等于3名，那么就只设置前3名教师讲课
//            for (int i = 0; i < lessonRecordList.size(); i++) {
//                LessonRecord lessonRecord = lessonRecordList.get(i);
//                if (i < (lessonRecordList.size()/3)) {
//                    lessonRecord.setTeacher(firstTeacher);
//                } else if ((i>=(lessonRecordList.size()/3))&&(i<(lessonRecordList.size()*2/3))) {
//                    lessonRecord.setTeacher(secondTeacher);
//                } else {
//                    lessonRecord.setTeacher(thirdTeacher);
//                }
//            }
//        }
//    }

    /**
     * 写课程和类型
     * @param lessonRecordList 排课计划的list集合，需要对里面每一个元素进行课程和类型的设置
     * @param model M1-M8的课程类型
     * @return
     */
    private List<LessonRecord> setSubjectAndType(List<LessonRecord> lessonRecordList, String model) {
        //设置课程类
        LambdaQueryWrapper<Subject> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(model!=null,Subject::getModel,model);
        List<Subject> subjectList = subjectMapper.selectList(queryWrapper);
        for (int i = 0; i < lessonRecordList.size(); i++) {
            LessonRecord lessonRecord = lessonRecordList.get(i);
            lessonRecord.setSubject(subjectList.get(i).getName());
            //设置类型
            if (("M7-PA".equals(model))||("M8-PA".equals(model))||("M7-TA".equals(model))||("M8-TA").equals(model)) {
                lessonRecord.setType("实操");
            } else {
                lessonRecord.setType("理论");
            }
        }
        return lessonRecordList;
    }

    /**
     * 设置日期和时间和星期以及周六日
     * @param model
     * @param date
     * @param time
     * @return
     */
    public List<LessonRecord>  setDateAndTimeAndWeekend(String model, Date date, String time) {
        LambdaQueryWrapper<ShangKeRiQi> queryWrapper = new LambdaQueryWrapper<>();
        Integer hours =  this.getHours(model);
        queryWrapper.ge(date!=null,ShangKeRiQi::getDate,date).orderByAsc(date!=null,ShangKeRiQi::getDate).last("LIMIT "+hours);
        List<ShangKeRiQi> shangKeRiQiList = shangKeRiQiMapper.selectList(queryWrapper);
        List<Map<String, String>> mapList = shangKeRiQiList.stream().map(a -> {
            Date aDate = a.getDate();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            String formattedDate = simpleDateFormat.format(aDate);
            String weekend = a.getWeekend();
            Map<String, String> map = new HashMap<>();
            map.put("date", formattedDate);
            map.put("weekend", weekend);
            return map;
        }).sorted(Comparator.comparing(m -> m.get("date"), Comparator.naturalOrder())).collect(Collectors.toList());
        List<LessonRecord> lessonRecordList = new ArrayList<>();
        List<String> timeList = new ArrayList<>();
        for (int i = 0; i < 500; i++) {
            if (i%4 == 0) {
                timeList.add("08:30-10:30");
            } else if (i%4==1){
                timeList.add("10:30-12:30");
            } else if (i%4==2){
                timeList.add("13:30-15:30");
            } else {
                timeList.add("15:30-17:30");
            }
        }
        if ("M1".equals(model)) {
            //M1都是上午开课
            time="08:30-10:30";
        }
        int index = timeList.indexOf(time);
        for (int i = 0; i < mapList.size(); i++) {
            Map<String, String> map = mapList.get(i);
            String date1 = map.get("date");
            String weekend = map.get("weekend");
            LessonRecord lessonRecord = new LessonRecord();
            lessonRecord.setDate(commonUtils.mySqlDateFormatStringOfDashToDate(date1));
            lessonRecord.setWeekend(weekend);
            String nextTime = timeList.get(index);
            //设置时间
            setTime(i, lessonRecord, nextTime);
            index++;

            //设置上下午
            setMorningOrAfternoon(lessonRecord);

            //设置日期
            /*
            设置日期和星期的注意
            1 如果当前时间是8：30-10：30且不是第一个元素，就找前面一个元素的日期加1
            2 如果当天时间不是8：30-10：30，就找上一个元素的时间
             */
            setDateAndWeekend(mapList, lessonRecordList, i, lessonRecord);
            lessonRecordList.add(lessonRecord);
        }
        LessonRecord lessonRecord = lessonRecordList.get(0);
        if (lessonRecord != null&&"M1".equals(model)) {
            lessonRecord.setTime("09:00-10:00");
        }
        return lessonRecordList;
    }

    /**
     * 每一个循环中设置星期和日期
     * @param mapList 传入的按照日期顺序排列的ArrayList集合，里面是一个个Map集合，map集合里有两个key，一个key是date，一个key是date对应的weekend
     * @param lessonRecordList 排课计划的list集合，需要对里面每一个元素进行日期和星期的设置
     * @param i 循环的索引
     * @param lessonRecord lessonRecordList里的单个元素
     */
    public void setDateAndWeekend(List<Map<String, String>> mapList, List<LessonRecord> lessonRecordList, int i, LessonRecord lessonRecord) {
        String time1 = lessonRecord.getTime();
        if ((i != 0)){
            if (("08:30-10:30").equals(time1)) {
                //找到上一个元素
                LessonRecord previousLessonRecord = lessonRecordList.get(i - 1);
                //找到上一个元素的日期
                Date date1 = previousLessonRecord.getDate();
                String previousLessonRecordDate = commonUtils.mySqlDateFormatDateDashToString(date1);
                //找到上一个元素的下一个日期
                //在mapList里找lessonRecordDate对应的weekend
                Optional<Map<String, String>> foundMap = mapList.stream().filter(m ->
                        m.get("date").equals(previousLessonRecordDate)
                ).findFirst();
                if (foundMap.isPresent()) {
                    int foundIndex = mapList.indexOf(foundMap.get());
                    if (foundIndex + 1 < mapList.size()) {
                        Map<String, String> nextMap = mapList.get(foundIndex + 1);
                        // 处理下一个索引位置的 Map 集合
                        String nextDate = nextMap.get("date");
                        String nextWeekend = nextMap.get("weekend");
                        lessonRecord.setDate(commonUtils.mySqlDateFormatStringOfDashToDate(nextDate));
                        lessonRecord.setWeekend(nextWeekend);
                    }
                }
            } else {
                //就找上一个元素的时间
                //找到上一个元素
                LessonRecord previousLessonRecord = lessonRecordList.get(i - 1);
                //找到上一个元素的日期
                //设置周六日
                Date previousLessonRecordDate = previousLessonRecord.getDate();
                String previousLessonRecordWeekend = previousLessonRecord.getWeekend();
                lessonRecord.setDate(previousLessonRecordDate);
                lessonRecord.setWeekend(previousLessonRecordWeekend);
            }
        }
    }

    /**
     * 设置时间 根据索引下标设置时间
     * @param i 索引下标
     * @param lessonRecord
     * @param nextTime
     */
    public void setTime(int i, LessonRecord lessonRecord, String nextTime) {
        //设置时间
        lessonRecord.setTime(nextTime);
//        if (i%4==0) {
//            lessonRecord.setTime(nextTime);
//        } else {
//            if (i%4==1){
//                lessonRecord.setTime(nextTime);
//            } else if (i%4==2){
//                lessonRecord.setTime(nextTime);
//            } else {
//                lessonRecord.setTime(nextTime);
//            }
//        }
    }

    /**
     * 设置上下午
     * @param lessonRecord
     */
    public void setMorningOrAfternoon(LessonRecord lessonRecord) {
        if (("08:30-10:30".equals(lessonRecord.getTime()))||("10:30-12:30".equals(lessonRecord.getTime()))) {
            lessonRecord.setMorningOrAfternoon("上午");
        } else {
            lessonRecord.setMorningOrAfternoon("下午");
        }
    }

    /**
     * 根据课程模块查找课时
     * @param model
     * @return
     */
    @Override
    public Integer getHours(String model) {
        if ("M1".equals(model)) {
            //由于M1有一个入学须知和安全教育，所以多一节课
            return ModelEnum.M1.getHours()+1;
        } else if ("M2".equals(model)) {
            return ModelEnum.M2.getHours();
        } else if ("M3".equals(model)) {
            return ModelEnum.M3.getHours();
        }else if ("M4".equals(model)) {
            return ModelEnum.M4.getHours();
        } else if ("M5".equals(model)) {
            return ModelEnum.M5.getHours();
        } else if ("M6".equals(model)) {
            return ModelEnum.M6.getHours();
        } else if (("M7-PA".equals(model))||("M7-TA".equals(model))) {
            return ModelEnum.M7.getHours();
        } else {
            return ModelEnum.M8.getHours();
        }
    }



    /**
     * 获得班级编号，班级编号是sql中lessonsrecord的remark字段
     *
     * @return
     */
    @Override
    public List<String> getClassNum() {
        List<String> list = lessonRecordMapper.selectClassNum();
        return list;
    }
}
